<template>
	<view>
		<!-- <uni-nav-bar title="登陆"></uni-nav-bar> -->
		<text class="title">登陆</text>
		<view >
			<image src="../../static/login/bg.png" mode="" class="bg"></image>
			<image src="../../static/login/icon.png" mode="" class="icon"></image>
		</view>
		<view id="login">
			<view class="login-main">
				<view class="user enter">
					<image src="../../static/login/user.png" mode="" class="user-icon"></image>
					<input type="text" value="" placeholder="请输入用户名" class="input" placeholder-style="color:#e6e6e6;"  v-model="userInfo.username"/>
				</view>
				<view class="pass enter">
					<image src="../../static/login/password.png" mode="" class="user-icon"></image>
					<input type="text" value="" placeholder="请输入密码" class="input" placeholder-style="color: #e6e6e6;" v-model="userInfo.password"/>
				</view>
				<view class="text">
					<text @tap="register">立即注册</text>
					<text>忘记密码</text>					
				</view>
				<button type="default" id="btn-login" @tap="Login(userInfo)">登陆</button>
			</view>
			<view class="login-style-text">
				<text>其他登陆方式</text>
			</view>
			<view class="login-style">
				<view class="item" v-for="item in loginStyle" :key="item.id">
					<image :src="item.imgSrc" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginStyle:[
					{id:1,imgSrc:'../../static/login/qq.png'},
					{id:2,imgSrc:'../../static/login/wx.png'},
					{id:3,imgSrc:'../../static/login/zfb.png'},
					{id:4,imgSrc:'../../static/login/phone.png'}
				],
				userInfo:{
					username: "13808195362",
					password: "chino",
				}
			}
		},
		onLoad() {
		},
		methods: {
			async Login(userInfo){
				const res=await this.$http.users.login(userInfo);
				if(res.code==200){
					console.log(res.data);
					// 登录成功把token和手机号存到本地和把用户信息放到全局
					uni.setStorageSync('token',res.data.token);
					uni.setStorageSync('username',res.data.username);
					getApp().globalData.userInfo=res.data;
					uni.switchTab({
						url:'/pages/index/index'
					})
				}
			},
			// 立即注册
			register(){
				uni.navigateTo({
					url:'/pages/register/register'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>  
.title{
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	top: 60rpx;
	font-size: 40rpx;
	color: white;
	font-weight: bold;
}
.bg{
	width: 100%;
	height: 400rpx;
}
.icon{
	width: 168rpx;
	height: 168rpx;
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	top: 320rpx;
	
}
#login{
	margin-top: 80rpx;
	padding:24rpx;
	.login-main{
		padding-left: 30rpx;
		padding-right: 30rpx;
		height: 500rpx;
		padding-top: 106rpx;
		// border: 1px solid black;
		border-radius: 20rpx;
		box-shadow: 0px 0px 5px #e6e6e6;
		.text{
			margin-top: 36rpx;
			margin-bottom: 86rpx;
			display: flex;
			justify-content: space-between;
			text:nth-child(1){
				color: #3476fe;
			}
			text:nth-child(2){
				color: #e6e6e6;
			}
		}
	}
	.enter{
		display: flex;
		align-items: center;
		height: 86rpx;
		border-bottom: 1rpx solid #e6e6e6;
		.user-icon{
			width: 30rpx;
			height: 36rpx;
		}
		.input{
			margin-left: 30rpx;
		}
	}
	.pass{
		margin-top: 20rpx;
	}
	#btn-login{
		color: white;
		font-family:bold ;
		border: none;
		font-size: 28rpx;
		border-radius: 52rpx;
		padding: 10rpx;
		// background-color: #3476fe;
		background-image: linear-gradient(to bottom ,#4fa4f3,#3476fe);
	}
	.login-style-text{
		text-align: center;
		margin-top: 48rpx;
		font-size: 28rpx;
		color: #a6a6a6;
	}
}
.login-style{
	display: flex;
	width: 484rpx;
	justify-content: space-around;
	margin: 0 auto;
	margin-top: 50rpx;
	.item{
		image{
			height: 76rpx;
			width: 76rpx;
		}
	}
}
</style>
